/**
 * Project  : monkey
 * Author   : Wu Tian Qiang
 * Date     : 2016/10/26 15:41:10
 */
Ext.define('Monkey.view.role.ViewRolePermissionWindow', {
    extend: 'Ext.window.Window',

    closable: true,
    resizable: true,
    constrain: true,
    constrainHeader: true,
    modal: true,
    frameHeader: false,
    frame: true,
    maximizable: false,
    layout: 'fit',
    width: 500,
    height: 480,
    roleId: '',
    initComponent: function () {
        var me = this;
        if (Ext.isEmpty(me.roleId)) {
            Ext.raise('roleId属性不能为空');
        }
        var store = Ext.create('Monkey.store.BaseStore', {
            fields: [
                {name: 'id', type: 'int'},
                {name: 'actualIdentity', type: 'string'}, {
                    name: 'icon', type: 'string',
                    mapping: function (data) {
                        console.log(data);
                        return data.menu.icon;
                    }
                }, {
                    name: 'menu', type: 'string',
                    mapping: function (data) {
                        return data.menu.name;
                    }
                }, {
                    name: 'description', type: 'string',
                    mapping: function (data) {
                        return data.permission.description;
                    }
                }, {
                    name: 'permission', type: 'string',
                    mapping: function (data) {
                        return data.permission.name;
                    }
                }
            ],
            autoLoad: true,
            proxy: {
                type: 'ajax',
                pageParam: 'page.pn',
                limitParam: 'page.size',
                url: Monkey.URL.SERVER_URL + "/m/role/permission.json",
                extraParams: {
                    fields: 'id,menu[name:icon],permission[name:description],role[name],actualIdentity',
                    roleId: me.roleId
                },
                reader: {
                    type: 'json',
                    totalProperty: 'data.totalAmount',
                    rootProperty: 'data.elements'
                }
            }
        });
        me.items = [{
            border: false,
            xtype: 'grid',
            store: store,
            bbar: {
                xtype: 'pagingtoolbar',
                pageSize: 10,
                store: store,
                displayInfo: true,
                plugins: new Ext.ux.ProgressBarPager()
            },
            columns: [
                {width: 30, xtype: 'rownumberer'},
                {text: 'id', dataIndex: 'id', hidden: true},
                {
                    text: '菜单资源',
                    xtype: 'templatecolumn',
                    tpl: '<img style="vertical-align:middle;" src="{icon}">&nbsp;<span style="vertical-align:middle;">{menu}</span>',
                    flex: 1
                },
                {text: '操作权限', dataIndex: 'permission', flex: 1},
                {text: '权限路径', dataIndex: 'actualIdentity', flex: 1},
                {text: '操作描述', dataIndex: 'description',width:150}
            ]
        }];
        me.callParent();
    }
});